package org.execute.tool.数据提取;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class JsonTweet {
    public static void main(String[] args) {
        String filePath = "E:\\test\\test.txt"; // 替换为你的文本文件路径

        try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
            String line;
            while ((line = reader.readLine()) != null) {

                Tweet tweet = com.alibaba.fastjson.JSON.parseObject(line, Tweet.class);
                System.out.println(JSON.toJSONString(tweet));


                // 解析每一行JSON数据
                JSONObject jsonObject = JSON.parseObject(line);

                // 提取 _source 字段
                JSONObject sourceObject = jsonObject.getJSONObject("_source");
//                Tweet tweetSource = sourceObject.toJavaObject(Tweet.class);

                // 打印 _source 字段的内容
//                System.out.println(sourceObject.toJSONString());
            }
        } catch (IOException e) {
            System.out.println("文件读写错误： " + e.getMessage());
        }
    }
}
